package com.yc.movie.service.impl;

import com.yc.movie.entity.MovieInfo;
import com.yc.movie.mapper.MovieInfoMapper;
import com.yc.movie.service.IMovieInfoService;
import com.yc.movie.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MovieInfoServiceImpl implements IMovieInfoService {


    private MovieInfoMapper mapper;
    @Override
    public Map<String,Object> finds(Map<String, Object> map) {

        System.out.println(map);
        if(null!=map && null!=map.get("page") && null != map.get("limit")){
            map.put("page",Integer.parseInt(map.get("page").toString()));
            map.put("limit",Integer.parseInt(map.get("limit").toString()));
        }


        SqlSession session = MybatisUtil.getSession();
        mapper = session.getMapper(MovieInfoMapper.class);

        List<MovieInfo > list = mapper.finds(map);
        System.out.println(list);
        int total = mapper.total(map);
        //创建HashMap存储数据
        Map<String,Object> m = new HashMap<>();
        if(null == list || list.isEmpty()){
            m.put("code",600);
            m.put("msg","暂无数据");
        }
        else{
            m.put("code",200);
            m.put("msg","成功");
            m.put("data",list);
            m.put("count",total);
        }

        MybatisUtil.close(session);

        return m;
    }
}
